package com.uenpay.im.ui.old.activity.wallet;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;

import org.json.JSONException;
import org.json.JSONObject;

public class CashInvokItem extends HttpInvokeItem {

	public class CashInvokItemResult extends HttpInvokeResult {
		public String cashid;
		public String bankcard;
		public String bankname;
		public String accountname;
	}

	public CashInvokItemResult getOutput() {
		return (CashInvokItemResult) GetResultObject();
	}

	public CashInvokItem(String amount, String paypassword) {
		String url = APIConfiguration.getBaseUrl() + "Purse/Purse/cash?amount="
				+ amount + "&paypassword=" + paypassword + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		CashInvokItemResult result = new CashInvokItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
			JSONObject jsonObject = json.optJSONObject("data");
			if (jsonObject == null) {
				return result;
			}else{
				result.cashid = jsonObject.optString("cashid");
				result.bankcard = jsonObject.optString("bankcard");
				result.accountname = jsonObject.optString("accountname");
				result.bankname = jsonObject.optString("bankname");
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
